//-----------------------------------------------------------------------
// <copyright file="PremiumFeature.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Live.Messenger
{
    using System;
    using System.ComponentModel;
    using Microsoft.Live.Core;

    /// <summary>
    /// Specifies a premium feature available to the User.
    /// </summary>
    public sealed class PremiumFeature : INotifyPropertyChanged
    {
        private readonly MessengerEntity entity;

        internal PremiumFeature(object obj)
        {
            this.entity = new MessengerEntity(obj);
            this.entity.AttachEvent("PropertyChanged", this.OnPropertyChanged);
        }

        /// <summary>
        /// Gets whether the feature is provisioned.
        /// </summary>
        public bool Provisioned
        {
            get { return this.entity.GetProperty<bool>("Provisioned"); }
        }

        /// <summary>
        /// Gets whether the feature is enabled.
        /// </summary>
        public bool Enabled
        {
            get { return this.entity.GetProperty<bool>("Enabled"); }
        }

        /// <summary>
        /// Gets whether the feature is suspended.
        /// </summary>
        public bool Suspended
        {
            get { return this.entity.GetProperty<bool>("Suspended"); }
        }

        #region INotifyPropertyChanged Members

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        private void OnPropertyChanged(object sender, MessengerEventArgs e)
        {
            this.OnPropertyChanged(
                new PropertyChangedEventArgs(
                    e.Entity.GetProperty<string>("PropertyName")));
        }

        /// <summary>
        /// Raises the <see cref="PropertyChanged"/> event.
        /// </summary>
        private void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, e);
            }
        }
    }
}
